<script>
//图表工具箱配置
import BaseConfig from '../BaseConfig';
import * as ConfigEnum from '../config/config-enum';

export default {
  name: 'ToolConfig',
  mixins: [BaseConfig],
  data() {
    return {
      chartTools: ConfigEnum.TOOLBOX_TYPE,
      selectedTools: [],
    };
  },
  created() {
    this.selectedTools = Object.keys(this.chartOptions.extend.toolbox.feature);
  },
  methods: {
    updateTools() {
      var feature = {};
      this.selectedTools.forEach(p => (feature[p] = {}));
      this.chartOptions.extend.toolbox.feature = feature;
      this.updateOptions();
    },
  },
};
</script>

<template>
  <div>
    <Row>
      <Col span="8">
      <span>是否显示：</span>
      </Col>
      <Col span="16">
      <Switch
        v-model="chartOptions.extend.toolbox.show"
        @on-change="updateOptions">
        <span slot="open">是</span>
        <span slot="close">否</span>
      </Switch>
      </Col>
    </Row>
    <div
      v-if="chartOptions.extend.toolbox.show"
      class="switch-box">
      <Row>
        <Col span="8">
        <span>可用工具：</span>
        </Col>
        <Col span="16">
        <Select
          v-model="selectedTools"
          multiple
          @on-change="updateTools">
          <Option
            v-for="item in chartTools"
            :value="item.value"
            :key="item.value">{{ item.key }}</Option>
        </Select>
        </Col>
      </Row>
    </div>
  </div>
</template>

<style>
</style>
